﻿using Microsoft.Extensions.Configuration;
using Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace vueweb
{
	
	public static class RedisHelper
	{
		private static SentinelConfig 哨兵配置
		{
			get
			{
				if (Singleton<SentinelConfig>.Instance == null)
				{
					Singleton<SentinelConfig>.Instance = CommonTools.Config.GetSection("root:redis").Get<SentinelConfig>();
				}
				return Singleton<SentinelConfig>.Instance;
			}
		}

		public static RedisClientsManagerWrap GetRedisClientsManager(int database=-1)
		{
			SentinelConfig realConfig = new SentinelConfig
			{
				AuthPass = 哨兵配置.AuthPass,
				DefaultDatabase = database > 0 ? database : 哨兵配置.DefaultDatabase,
				InstanceName = 哨兵配置.InstanceName,
				ScanForOtherSentinels = 哨兵配置.ScanForOtherSentinels,
				MasterGroup = 哨兵配置.MasterGroup,
				Hosts = 哨兵配置.Hosts.ToOther<string[]>()
			};
			
			return new RedisClientsManagerWrap(realConfig);
		}
	}
}
